package com.ruoyi.web.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.web.domain.TLink;
import com.ruoyi.web.service.ITLinkService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 友情链接Controller
 * 
 * @author ruoyi
 * @date 2023-10-08
 */
@RestController
@RequestMapping("/link")
public class TLinkController extends BaseController
{
    @Autowired
    private ITLinkService tLinkService;

    /**
     * 查询友情链接列表
     */
    @RequiresPermissions("web:link:list")
    @GetMapping("/list")
    public TableDataInfo list(TLink tLink)
    {
        startPage();
        List<TLink> list = tLinkService.selectTLinkList(tLink);
        return getDataTable(list);
    }

    /**
     * 导出友情链接列表
     */
    @RequiresPermissions("web:link:export")
    @Log(title = "友情链接", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TLink tLink)
    {
        List<TLink> list = tLinkService.selectTLinkList(tLink);
        ExcelUtil<TLink> util = new ExcelUtil<TLink>(TLink.class);
        util.exportExcel(response, list, "友情链接数据");
    }

    /**
     * 获取友情链接详细信息
     */
    @RequiresPermissions("web:link:query")
    @GetMapping(value = "/{tid}")
    public AjaxResult getInfo(@PathVariable("tid") Long tid)
    {
        return success(tLinkService.selectTLinkByTid(tid));
    }

    /**
     * 新增友情链接
     */
    @RequiresPermissions("web:link:add")
    @Log(title = "友情链接", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TLink tLink)
    {
        return toAjax(tLinkService.insertTLink(tLink));
    }

    /**
     * 修改友情链接
     */
    @RequiresPermissions("web:link:edit")
    @Log(title = "友情链接", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TLink tLink)
    {
        return toAjax(tLinkService.updateTLink(tLink));
    }

    /**
     * 删除友情链接
     */
    @RequiresPermissions("web:link:remove")
    @Log(title = "友情链接", businessType = BusinessType.DELETE)
	@DeleteMapping("/{tids}")
    public AjaxResult remove(@PathVariable Long[] tids)
    {
        return toAjax(tLinkService.deleteTLinkByTids(tids));
    }
}
